package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.CharBookConfigTable;
import com.lineage.server.datatables.storage.CharBookConfigStorage;
import com.lineage.server.templates.L1BookConfig;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CharBookConfigReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final CharBookConfigStorage _storage = (CharBookConfigStorage)new CharBookConfigTable();
  
  private static CharBookConfigReading _instance;
  
  public static CharBookConfigReading get() {
    if (_instance == null)
      _instance = new CharBookConfigReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1BookConfig get(int objectId) {
    L1BookConfig tmp;
    this._lock.lock();
    try {
      tmp = this._storage.get(objectId);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1BookConfig storeCharBookConfig(int objectId, byte[] data) {
    L1BookConfig tmp;
    this._lock.lock();
    try {
      tmp = this._storage.storeCharBookConfig(objectId, data);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void updateCharBookConfig(int objectId, byte[] data) {
    this._lock.lock();
    try {
      this._storage.updateCharBookConfig(objectId, data);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateCharBookMaxSize(int objectId, int maxSize) {
    this._lock.lock();
    try {
      this._storage.updateCharBookMaxSize(objectId, maxSize);
    } finally {
      this._lock.unlock();
    } 
  }
}
